home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / mj92.lha / 4play / 4Play.txt < prev    next >
Encoding:
Text File  |  1992-05-27  |  9.0 KB  |  189 lines

  1. (c)  Copyright 1992 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and is provided "as is" without warranty of any kind, either expressed
  4. or implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7.  
  8.  
  9. Four Can Play-Supporting Parallel Port Joysticks
  10.  
  11. by Chris Ludwig
  12.  
  13.  
  14.  
  15. One of the many reasons people buy computer-based products is to use
  16. them as an ``entertainment box''.  Amiga users are no exception in this
  17. regard.  The Amiga has all the ingredients needed to be a great game
  18. machine; fast high-quality graphics, high-fidelity stereo sound, fast
  19. processor, and built-in joystick ports.
  20.  
  21. With this level of hardware support, it's no wonder that some of the
  22. industry's best games continue to be written for the Amiga first.
  23.  
  24. The only kind of games that don't currently lend themselves to the
  25. Amiga's built-in hardware are those that are meant to be played by more
  26. than two players simultaneously.  Several types of games fall into this
  27. category, the most notable being the scrolling cooperative.  This type
  28. of game, where up to four players control on-screen versions of
  29. themselves, is quite popular in video arcades.  Another format that
  30. lends itself to having more than two joysticks is the board game
  31. simulation.  It's simply easier to play a four player board game if
  32. each player has his or her own control.
  33.  
  34. Because the Amiga has only two joystick ports, there are currently only
  35. a small number of ``greater than two'' player games available.  So how
  36. do these games get around the two port limitation?  The developers of
  37. these games have worked up a little bit of external hardware that
  38. remaps some parallel port input lines as two more joystick ports for
  39. single button joysticks.
  40.  
  41. Fortunately, these developers are all using the same wiring in their
  42. interfaces.  Unfortunately, neither the interface nor its
  43. specifications have been widely available.
  44.  
  45. This article explains the construction of these parallel port joystick
  46. adapters (this article refers to them ``+2'' adapters), and
  47. demonstrates a coding strategy which will allow your software to access
  48. these two new ports.  Though the instructions are fairly simple, if not
  49. done properly, it is possible to damage your computer, so Commodore
  50. does not recommend that you build these yourself.  This information is
  51. provided for your convenience and is expressly subject to the
  52. disclaimer and warnings found at the beginning of this publication.
  53.  
  54.  
  55.  
  56.  
  57. Building the ``+2'' Interface
  58.  
  59. The interface that these two extra joystick ports require is quite
  60. straightforward in design and does not require any power.  Essentially,
  61. two male 9-pin ``d-sub'' connectors (the type commonly used for
  62. joystick ports) are wired directly to a 25-pin ``d-sub'' connector.
  63.  
  64. The gender of the 25-pin connector depends on the Amiga model.  Amiga
  65. 1000 computers have a non-standard, male 25-pin parallel port, so the
  66. Amiga 1000 adapters will need a female connector.  All other Amigas
  67. have standard female 25-pin parallel ports, so adapters for A500, A600,
  68. A2000, A3000, A3000T, and CDTV units should have a male 25-pin
  69. connector.
  70.  
  71. The only difference between the requirements for the A1000 ``+2''
  72. adapter and the ``+2'' adapter for the rest of the Amiga/CDTV product
  73. line is the gender.  The ``+2'' adapter only uses parallel port pins
  74. that all Amigas/CDTVs have in common.  These particular pins were
  75. chosen so that one ``+2'' adapter and a gender changer could connect
  76. two joysticks to any existing Amiga.  Because some of the unused pins
  77. carry voltages, only wire the pins specified in the chart!  Doing
  78. otherwise can destroy components inside the Amiga!
  79.  
  80. Parallel function       Parallel port   JOY3    JOY4    Joystick function
  81.                         (25 pin male)   (9pm)   (9pm)
  82. -----------------       -------------   -----   -----   -----------------
  83. Data bit 0              2               1               JOY3 UP
  84. Data bit 1              3               2               JOY3 DOWN
  85. Data bit 2              4               3               JOY3 LEFT
  86. Data bit 3              5               4               JOY3 RIGHT
  87.  
  88. Data bit 4              6                       1       JOY4 UP
  89. Data bit 5              7                       2       JOY4 DOWN
  90. Data bit 6              8                       3       JOY4 LEFT
  91. Data bit 7              9                       4       JOY4 RIGHT
  92.  
  93. Busy                    11                      6       JOY4 FIRE
  94. Select (Online)         13              6               JOY3 FIRE
  95.  
  96. ground                  18                      8       JOY4 GROUND
  97. ground                  19              8               JOY3 GROUND
  98.  
  99.  
  100.  
  101.  
  102.  
  103. Housing the Interface
  104.  
  105. Parallel function       Parallel port   JOY3    JOY4    Joystick function
  106.                         (25 pin male)   (9pm)   (9pm)
  107. -----------------       -------------   ----    ----    -----------------
  108. Data bit 0              2               1               JOY3 UP
  109. Data bit 1              3               2               JOY3 DOWN
  110. Data bit 2              4               3               JOY3 LEFT
  111. Data bit 3              5               4               JOY3 RIGHT
  112.  
  113. Data bit 4              6                       9       JOY4 UP
  114. Data bit 5              7                       10      JOY4 DOWN
  115. Data bit 6              8                       11      JOY4 LEFT
  116. Data bit 7              9                       12      JOY4 RIGHT
  117.  
  118. Busy                    11                      22      JOY4 FIRE
  119. Select (Online)         13              14              JOY3 FIRE
  120.  
  121. ground                  18                      24      JOY4 GROUND
  122. ground                  19              16              JOY3 GROUND
  123.  
  124. For development purposes, you can construct a ``+2'' adapter from two
  125. 25-pin male d-sub connectors.  One connector attaches to the parallel
  126. port, while the other accepts the two 9-pin female joystick plugs.
  127. Simply build the ``number 3'' joystick connector into the leftmost 9
  128. pins, and the ``number 4'' connector into the rightmost 9 pins.  The
  129. pin-outs for this setup are in the ``Non-Production +2 Interface''
  130. chart above.
  131.  
  132. This arrangement is attractive to developers primarily because it has
  133. few parts and it's easy to construct.  It is appropriate only for
  134. developer use and testing.  Do not consider it for any sort of user
  135. distribution, because the connectors for certain brands of joysticks
  136. are too big to fit side by side into a 25-pin connector.  Users will
  137. become quite irate upon finding that they can't use their ``wiz-stik
  138. 5000'' with their 4 player game adapter.
  139.  
  140. With this in mind, adapters intended for use by end users should be
  141. built into some sort of casework.  The box should include two suitably
  142. spaced joystick connectors, and a cable that allows the user to easily
  143. attach the adapter to the parallel port.  Be sure that the cable is
  144. long enough to allow users to place the adapter where they can get to
  145. it easily.
  146.  
  147. Alternatively, the device could simply be a pair of long cables in a
  148. ``Y'' shape, with a parallel connector at the base of the ``Y'', and
  149. joystick connector on the other ends.  Such an adapter would probably
  150. be the cheapest way to go.
  151.  
  152. Developers must caution end users to turn their computer's power off
  153. before plugging in a ``+2'' adapter.  This will prevent users from
  154. accidentally destroying the 8520 chips which control the parallel port.
  155. To further prevent 8520 damage, developers should choose 25-pin
  156. connectors without a metal case or shield.  While plugging the device
  157. in, it's rather easy to accidentally brush (and short) the metal
  158. shields of certain connectors against the pins of the parallel port.
  159.  
  160. No matter what the decision regarding implementation, remember that
  161. game players can be quite rough.  All cables should be suitably long,
  162. and all connectors should utilize a proper strain relief system.
  163.  
  164.  
  165. Supporting the Interface in Software
  166.  
  167. Because this ``+2'' joystick adapter attaches to the parallel port,
  168. supporting it in software is simply a matter of reading the correct
  169. lines on the parallel port.
  170.  
  171. Many Amiga game programmers make the decision to throw away the OS and
  172. directly manipulate the hardware.  These programmers will no doubt come
  173. up with their own personal scheme for reading the appropriate
  174. information from the port.  Other, more forward thinking developers,
  175. may want to write their software in such a way as to be compatible with
  176. the OS.
  177.  
  178. The following pair of code samples work in tandem to demonstrate one
  179. method of reading the necessary information from the parallel port in
  180. an OS friendly manner.  The C program 4play.c is a simple example that
  181. demonstrates how to access the assembly functions.  The assembly
  182. language program properly allocates the parallel port and any necessary
  183. signal lines, warning the OS not to let any other applications use
  184. them.  Other assembly routines do the actual hardware level reading and
  185. place the joystick values into C variables.  A cleanup routine releases
  186. the port and signal lines.  The example does not mask out the
  187. directional or fire button bits, it only prints the raw joystick data.
  188. I'll leave it as an exercise for the reader to interpret the meaning of
  189. the raw data.